package com.atguigu.gmall.mq.consumer;

import com.atguigu.gmall.mq.config.DeadLetterConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/26  23:38
 * @description：TODO
 */
@Component
public class DeadLetterConsumer {

    //接收消息  延迟
    //方法一：配置式 死机延迟消息配置
    //方法二：注解式

    @RabbitListener(queues = DeadLetterConfig.queue_dead_2)
    public void deadLetterMessage(String msg, Message message, Channel channel){
        try {
            System.out.println("接收的消息：" + msg);
            System.out.println("接收的时间：" + new Date());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
